<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        body {
            background: url(images/bg_green.jpg) no-repeat center center;
            background-size: cover;
        }
        .nav {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 10px;
            width: 700px;
            height: 200px;
            margin: 100px auto;
            border: 1px solid #ccc;
            padding: 10px;
            background-color: rgba(255, 255, 255, 0.7);
        }
        img {
            width: 150px;
            height: 200px;
            object-fit: cover;
            border-radius: 8px;
            cursor: pointer;
            transition: transform 0.3s ease, opacity 0.3s ease;
            border: 3px solid transparent; /* 预留边框位 */
        }
        img:hover {
            transform: scale(1.1);
            opacity: 0.8;
        }
        /* 选中状态边框 */
        img.selected {
            border-color: #007bff;
            box-shadow: 0 0 6px #007bff;
        }
    </style>
</head>
<body>
    <div class="nav">
        <img src="images/bg_green.jpg" alt="">
        <img src="images/bg_gray_orange.jpg" alt="">
        <img src="images/bg_purple.jpg" alt="">
        <img src="images/bg_yellow.jpg" alt="">
    </div>

    <script>
        const nav = document.querySelector('.nav');
        const imgs = nav.querySelectorAll('img');

        imgs.forEach(img => {
            img.addEventListener('click', function() {
                imgs.forEach(i => i.classList.remove('selected'));
                this.classList.add('selected');
                document.body.style.backgroundImage = `url(${this.src})`;
            });
        });
    </script>
</body>
</html>